<%@page pageEncoding="UTF-8" %>
<%@page import="getools4me.UserManager"%>
<%@page import="com.google.appengine.api.users.User"%>
<%@page import="com.google.appengine.api.users.UserService"%>
<%@page import="com.google.appengine.api.users.UserServiceFactory"%>
<%
	UserService us = UserServiceFactory.getUserService();
	User user = us.getCurrentUser();
	String thisUrl = request.getRequestURI();
	String loginURL = us.createLoginURL(thisUrl);
	String logoutURL = us.createLogoutURL(thisUrl);
%>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/blog/css/common.css" />
<link rel="stylesheet" type="text/css" href="/blog/css/menu.css" />
<link rel="stylesheet" type="text/css" href="/blog/css/editor.css" />
<script type="text/javascript" src="/blog/js/common.js"></script>
<title>New Blog</title>
</head>
<body onload="document.getElementByID('title').focus();">

<div class="menu">
	<ul>
		<li><a href="/blog/page/home.jsp">Home</a></li>
		<li><a href="/blog/page/all.jsp">All</a></li>
		<li><%if(UserManager.isLogin()){ %><a href="<%=UserManager.getLogoutURL(request)%>">Logout</a><%}else{ %><a href="<%=UserManager.getLoginURL(request)%>">Login</a><%} %></li>
		<li><%if(UserManager.isAdmin()){ %>
		<a href="/blog/page/new.jsp">New</a><%} %>
		</li>
	</ul>
</div>


<%if(user==null){ %> 
	<div class="center">
		<h1><a href="<%=loginURL%>">Please Login ...</a></h1>
	</div>
<%}else if(!user.getEmail().equals("jpgtama@gmail.com")) { %>
	<div class="center">
		<h1>Welcome, Mr. <%=user.getNickname() %> !</h1>
		<i>Sorry, you are not admin.(<a href="<%=logoutURL%>">Logout</a>)    </i>
	</div>
<%}else{ %>



<div class="edit">

	<form action="/receive" method="post" enctype="multipart/form-data" name="newBlog" onsubmit="return setHiddenValue();">
		
		<div>
			<label>Title</label><span class="required">*</span>
			<input id="title" type="text" class="block">
		</div>
		<div>
			<label>Body</label><span class="required">*</span>
			<textarea id="content" class="block" rows="15"></textarea>
		</div>
		<div class="submit"><input type="submit" value="Submit"/></div>
		<input type="hidden" name="method" value="recevieBlog"/>
		<input type="hidden" name="posturl" value="/blog/page/home.jsp"/>
		<input type="hidden" class="commUnicode" name="author" value="<%=user==null?"":user.getNickname()%>">
		<input type="hidden" class="commUnicode" name="website" value="<%=request.getScheme()%>://<%=request.getServerName()%>:<%=request.getServerPort()%>">
		<input type="hidden" class="commUnicode" name="email" value="<%=user==null?"":user.getEmail()%>">
		<input type="hidden" class="commUnicode getValueFrom" name="title">
		<textarea class="commUnicode hidden getValueFrom" name="content"></textarea>
	</form>

</div>

<%} %>

<div class="footer">

	<iframe class="footer" src="/footer.html" frameborder="0" width="100%"></iframe>
	
</div>

<script type="text/javascript">
	var common = new Common();
	
	// change the value of hidden input 
	function setHiddenValue(){
		// find the element with the classname 'getValueFrom'
		var list = document.getElementsByClassName("getValueFrom");
		var i = 0;
		for(i=0;i<list.length;i++){
			var e = list[i];
			if(!document.getElementById(e.name).value) {
				alert(e.name + " can not be empty!");
				return false;
			}
			e.value = document.getElementById(e.name).value;
		}
		
		// convert to unicode
		common.convertCommUnicodeClassInputValueFromStringToUnicode();
		
		//
		return true;
	}
	
	
</script>



</body>
</html>